package cn.iocoder.yudao.module.system.controller.admin.facecompany;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.facecompany.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.facecompany.FaceCompanyDO;
import cn.iocoder.yudao.module.system.service.facecompany.FaceCompanyService;

@Tag(name = "管理后台 - 面试公司")
@RestController
@RequestMapping("/system/face-company")
@Validated
public class FaceCompanyController {

    @Resource
    private FaceCompanyService faceCompanyService;

    @PostMapping("/create")
    @Operation(summary = "创建面试公司")
    @PreAuthorize("@ss.hasPermission('system:face-company:create')")
    public CommonResult<Long> createFaceCompany(@Valid @RequestBody FaceCompanySaveReqVO createReqVO) {
        return success(faceCompanyService.createFaceCompany(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新面试公司")
    @PreAuthorize("@ss.hasPermission('system:face-company:update')")
    public CommonResult<Boolean> updateFaceCompany(@Valid @RequestBody FaceCompanySaveReqVO updateReqVO) {
        faceCompanyService.updateFaceCompany(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除面试公司")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:face-company:delete')")
    public CommonResult<Boolean> deleteFaceCompany(@RequestParam("id") Long id) {
        faceCompanyService.deleteFaceCompany(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得面试公司")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:face-company:query')")
    public CommonResult<FaceCompanyRespVO> getFaceCompany(@RequestParam("id") Long id) {
        FaceCompanyDO faceCompany = faceCompanyService.getFaceCompany(id);
        return success(BeanUtils.toBean(faceCompany, FaceCompanyRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得面试公司分页")
    @PreAuthorize("@ss.hasPermission('system:face-company:query')")
    public CommonResult<PageResult<FaceCompanyRespVO>> getFaceCompanyPage(@Valid FaceCompanyPageReqVO pageReqVO) {
        PageResult<FaceCompanyDO> pageResult = faceCompanyService.getFaceCompanyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FaceCompanyRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出面试公司 Excel")
    @PreAuthorize("@ss.hasPermission('system:face-company:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFaceCompanyExcel(@Valid FaceCompanyPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<FaceCompanyDO> list = faceCompanyService.getFaceCompanyPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "面试公司.xls", "数据", FaceCompanyRespVO.class,
                        BeanUtils.toBean(list, FaceCompanyRespVO.class));
    }

}